home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F18894_PremiershipTableFull.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-04-14  |  8.0 KB  |  176 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0"
  3.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4. <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
  5.  
  6. <xsl:key name="teams" match="result/home" use="@team"/>
  7. <xsl:key name="teams" match="result/away" use="@team"/>
  8. <xsl:key name="opposition" match="result/home" use="../away/@team"/>
  9. <xsl:key name="opposition" match="result/away" use="../home/@team"/>
  10. <xsl:key name="wins" match="result/away[@score > ../home/@score]" use="@team"/>
  11. <xsl:key name="wins" match="result/home[@score > ../away/@score]" use="@team"/>
  12. <xsl:key name="draws" match="result/away[@score = ../home/@score]" use="@team"/>
  13. <xsl:key name="draws" match="result/home[@score = ../away/@score]" use="@team"/>
  14. <!-- keys used to calc home/away results specifically -->
  15. <xsl:key name="home-teams" match="result/home" use="@team"/>
  16. <xsl:key name="home-opposition" match="result/away" use="../home/@team"/>
  17. <xsl:key name="home-wins" match="result/home[@score > ../away/@score]" use="@team"/>
  18. <xsl:key name="home-draws" match="result/home[@score = ../away/@score]" use="@team"/>
  19.  
  20. <xsl:template match="/">
  21.     <html>
  22.         <head>
  23.             <title>
  24.                 <xsl:value-of select="/results/@nation"/>
  25.                 <xsl:text> </xsl:text>
  26.                 <xsl:value-of select="/results/@sponsor"/>
  27.                 <xsl:text> </xsl:text>
  28.                 <xsl:value-of select="/results/@league"/>
  29.                 <xsl:text> (full home/away)</xsl:text>
  30.             </title>
  31.         </head>
  32.         <body>
  33.             <h3>
  34.                 <xsl:value-of select="/results/@nation"/>
  35.                 <xsl:text> </xsl:text>
  36.                 <xsl:value-of select="/results/@sponsor"/>
  37.                 <xsl:text> </xsl:text>
  38.                 <xsl:value-of select="/results/@league"/>
  39.                 <xsl:text> (full home/away)</xsl:text>
  40.             </h3>
  41.             <table border="0" bgcolor="Black" cellspacing="1" style="font-family: Courier New, Courier, monospace; font-size: 12;">
  42.                 <tr bgcolor="Silver">
  43.                     <th rowspan="2" valign="bottom">Pos</th>
  44.                     <th rowspan="2" valign="bottom">Team</th>
  45.                     <th rowspan="2" valign="bottom">Pld</th>
  46.                     <th colspan="5" align="center">Home</th>
  47.                     <th colspan="5" align="center">Away</th>
  48.                     <th colspan="5" align="center">Overall</th>
  49.                     <th width="20" rowspan="2" valign="bottom">GD</th>
  50.                     <th width="20" rowspan="2" valign="bottom">Pts</th>
  51.                 </tr>
  52.                 <tr bgcolor="Silver">
  53.                     <!-- Home record -->
  54.                     <th width="20">W</th>
  55.                     <th width="20">D</th>
  56.                     <th width="20">L</th>
  57.                     <th width="20">F</th>
  58.                     <th width="20">A</th>
  59.                     <!-- Away record -->
  60.                     <th width="20">W</th>
  61.                     <th width="20">D</th>
  62.                     <th width="20">L</th>
  63.                     <th width="20">F</th>
  64.                     <th width="20">A</th>
  65.                     <!-- Overall record -->
  66.                     <th width="20">W</th>
  67.                     <th width="20">D</th>
  68.                     <th width="20">L</th>
  69.                     <th width="20">F</th>
  70.                     <th width="20">A</th>
  71.                 </tr>
  72.                 <!-- apply template to each distinct team -->
  73.                 <xsl:apply-templates select="(/results/result/home|/results/result/away)[generate-id(.) = generate-id(key('teams',@team))]">
  74.                     <!-- sort primarily on points -->
  75.                     <xsl:sort select="(count(key('wins',@team)) * 3) + (count(key('draws',@team)))" data-type="number" order="descending"/>
  76.                     <!-- secondary sort by goal difference -->
  77.                     <xsl:sort select="sum(key('teams',@team)/@score) - sum(key('opposition',@team)/@score)" data-type="number" order="descending"/>
  78.                     <!-- final sort on goals scored -->
  79.                     <xsl:sort select="sum(key('teams',@team)/@score)" data-type="number" order="descending"/>
  80.                 </xsl:apply-templates>
  81.             </table>
  82.             <sub>
  83.                 <xsl:text>(Results up to and including </xsl:text>
  84.                 <!-- find max date - don't rely on results being sorted -->
  85.                 <xsl:variable name="last-date">
  86.                     <xsl:apply-templates select="/results/result/@date[1]" mode="find-max">
  87.                         <xsl:sort select="translate(.,'-','')" data-type="number" order="ascending"/>
  88.                     </xsl:apply-templates>
  89.                 </xsl:variable>
  90.                 <xsl:value-of select="concat(substring($last-date,9,2),'/',substring($last-date,6,2),'/',substring($last-date,1,4))"/>
  91.                 <xsl:text>)</xsl:text>
  92.             </sub>
  93.         </body>
  94.     </html>
  95. </xsl:template>
  96.  
  97. <xsl:template match="home|away">
  98.     <!-- store any nodesets used more than once -->
  99.     <xsl:variable name="games" select="key('teams',@team)"/>
  100.     <xsl:variable name="home-games" select="key('home-teams',@team)"/>
  101.     <!-- calculate anything that is used more than once -->
  102.     <!-- saves processing keys excessively -->
  103.     <xsl:variable name="played" select="count($games)"/>
  104.     <xsl:variable name="wins" select="count(key('wins',@team))"/>
  105.     <xsl:variable name="draws" select="count(key('draws',@team))"/>
  106.     <xsl:variable name="goals-for" select="sum($games/@score)"/>
  107.     <xsl:variable name="goals-against" select="sum(key('opposition',@team)/@score)"/>
  108.     <!-- home record calcs -->
  109.     <xsl:variable name="home-played" select="count($home-games)"/>
  110.     <xsl:variable name="home-wins" select="count(key('home-wins',@team))"/>
  111.     <xsl:variable name="home-draws" select="count(key('home-draws',@team))"/>
  112.     <xsl:variable name="home-goals-for" select="sum($home-games/@score)"/>
  113.     <xsl:variable name="home-goals-against" select="sum(key('home-opposition',@team)/@score)"/>
  114.     <!-- away record calcs -->
  115.     <xsl:variable name="away-played" select="$played - $home-played"/>
  116.     <xsl:variable name="away-wins" select="$wins - $home-wins"/>
  117.     <xsl:variable name="away-draws" select="$draws - $home-draws"/>
  118.     <xsl:variable name="away-goals-for" select="$goals-for - $home-goals-for"/>
  119.     <xsl:variable name="away-goals-against" select="$goals-against - $home-goals-against"/>
  120.     <!-- pre-calc cross row/col colour -->
  121.     <xsl:variable name="cross-colour" select="substring('E0E0E023E2A9',((position() mod 2)*6)+1,6)"/>
  122.     <!-- now display the table row -->
  123.     <tr bgcolor="#{substring('FFFFFF8AF7D6',((position() mod 2)*6)+1,6)}">
  124.         <!-- league position -->
  125.         <td align="right"><xsl:value-of select="position()"/></td>
  126.         <!-- team name -->
  127.         <td><xsl:value-of select="@team"/></td>
  128.         <!-- games played -->
  129.         <td align="right"><xsl:value-of select="$played"/></td>
  130.         <!-- HOME RECORD -->
  131.         <!-- wins -->
  132.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-wins"/></td>
  133.         <!-- draws -->
  134.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-draws"/></td>
  135.         <!-- losses -->
  136.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-played - $home-wins - $home-draws"/></td>
  137.         <!-- goals for -->
  138.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-goals-for"/></td>
  139.         <!-- goals against -->
  140.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-goals-against"/></td>
  141.         <!-- AWAY RECORD -->
  142.         <!-- wins -->
  143.         <td align="right"><xsl:value-of select="$away-wins"/></td>
  144.         <!-- draws -->
  145.         <td align="right"><xsl:value-of select="$away-draws"/></td>
  146.         <!-- losses -->
  147.         <td align="right"><xsl:value-of select="$away-played - $away-wins - $away-draws"/></td>
  148.         <!-- goals for -->
  149.         <td align="right"><xsl:value-of select="$away-goals-for"/></td>
  150.         <!-- goals against -->
  151.         <td align="right"><xsl:value-of select="$away-goals-against"/></td>
  152.         <!-- OVERALL RECORD -->
  153.         <!-- wins -->
  154.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$wins"/></td>
  155.         <!-- draws -->
  156.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$draws"/></td>
  157.         <!-- losses -->
  158.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$played - $wins - $draws"/></td>
  159.         <!-- goals for -->
  160.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$goals-for"/></td>
  161.         <!-- goals against -->
  162.         <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$goals-against"/></td>
  163.         <!-- goal difference -->
  164.         <td align="right"><xsl:value-of select="$goals-for - $goals-against"/></td>
  165.         <!-- points -->
  166.         <td align="right"><xsl:value-of select="($wins * 3) + $draws"/></td>
  167.     </tr>
  168. </xsl:template>
  169.  
  170. <xsl:template match="@date" mode="find-max">
  171.     <xsl:if test="position() = last()">
  172.         <xsl:value-of select="."/>
  173.     </xsl:if>
  174. </xsl:template>
  175.  
  176. </xsl:stylesheet>